package com.sx.baseproject.framework.adapter.binding;

import android.text.TextUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;

import androidx.databinding.BindingAdapter;

public class WebViewBinding {
    @BindingAdapter(value = {"webViewData"})
    public static void setWebData(WebView webView, String data) {
        if (webView != null) {
            WebSettings settings = webView.getSettings();
            settings.setJavaScriptEnabled(true);
            ////提高渲染的优先级
            settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
            //将图片调整到适合webview的大小
            settings.setUseWideViewPort(true);
            settings.setLoadWithOverviewMode(true);
            //不支持缩放
            settings.setSupportZoom(false);
            //隐藏原生缩放
            settings.setDisplayZoomControls(true);
            ////支持自动加载图片
            settings.setTextZoom(200);
            ;
            settings.setLoadsImagesAutomatically(true);
            //设置缓存 只能网络加载
            settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
            //设置操作文件
            settings.setAllowFileAccess(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setSupportMultipleWindows(true);
            settings.setAppCacheEnabled(true);
            settings.setDomStorageEnabled(true);
            settings.setBlockNetworkImage(false);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            if (!TextUtils.isEmpty(data)) {
                webView.loadDataWithBaseURL(null, data, "text/html", "UTF-8", null);
            }
        }
    }
}
